<template>
	<!-- 切换模板 -->
	<view class="selectTemplate u-p-x-60" style="padding-bottom: 100rpx;">
		<!-- 模板 -->
		<view style="margin-top: 50rpx;">
			<radio-group  style="display: flex; flex-wrap: wrap;justify-content: space-between;">
				<view v-for="(item, index) in dataInfo.listData" :key="index" style="display: flex;">
					<view style="display: flex;flex-direction: column;align-items: center;margin: 50rpx 0;">
						<view @click="previewImg([item.imgPath])" style="width: 280rpx;height: 500rpx;background-size: 100%;" :style="'background-image:url('+item.imgPath+');'" :class="item.menuNo == moNo?'imgStyle':''">
						</view>
						<view style="margin: 30rpx 0;">{{item.menuName}}</view>
						<radio @click="current=index" :value="item.menuName" :checked="item.menuNo == moNo" />
					</view>
				</view>
			</radio-group>
		</view>
		<!-- #ifdef MP-WEIXIN -->
			<view class="btn-bom" style="position: fixed;right: 0; bottom: 0;width: 750rpx;padding: 10rpx 30rpx;background-color: #FFFFFF;box-sizing: border-box;">
				<button type="primary" style="width: 100%;border-radius: 40rpx;" @click="$u.throttle(submit, 1000) ">确定</button>
			</view>
		<!-- #endif -->
	</view>
</template>
<script>
	import {queryClassAppMenu,updateCompanyModuleNo,editUsrCraftsman} from '@/common/api/auth.js'
	
	import {getToken,setToken} from '@/utils/token.js'
	export default {
		data(){
			return{
				current:0,
				dataInfo:{},
				moNo: getToken("version")==1?getToken('userInfo')['moduleNo']:getToken('complogin')['moduleNo']
			}
		},
		onNavigationBarButtonTap(e) {
			this.$u.throttle(this.submit(), 1000)
		},
		
		onLoad:function(){
			this.queryClassAppMenu()
		},
		methods:{
			submit(){
				let params = {
					moduleNo:this.dataInfo.listData && this.dataInfo.listData[this.current] && this.dataInfo.listData[this.current].menuNo
				}
				if(!params['moduleNo']){
					this.$u.toast('请选择模板')
					return
				}
				if(getToken('version') == 2){
					let arr =['ydylapp1001']
					if(params['moduleNo']!= 'ydylapp1001'){
						arr.push(params['moduleNo'])
					}
					params['chooseModuleNo'] = JSON.stringify(arr)
					params['companyId'] = getToken('useNum')
					updateCompanyModuleNo(params).then(res=>{
						if(res.data && res.data.code){
							this.$u.toast('切换成功')
							this.$store.commit('isFresh', true)
						}
						let dataComp = getToken('complogin')
						dataComp.moduleNo = params['moduleNo']
						setToken('complogin',dataComp)
						uni.navigateBack({})
					})
				}else{
					let arr =['ydylapp2001']
					if(params['moduleNo']!= 'ydylapp2001'){
						arr.push(params['moduleNo'])
					}
					params['chooseModuleNo'] = JSON.stringify(arr)
					params['craftsmanId'] = getToken('useNum')
					editUsrCraftsman(params).then(res=>{
						if(res.data && res.data.craftsmanId){
							setToken('userInfo',res.data)
							this.$u.toast('切换成功')
							this.$store.commit('isFresh', true)
							uni.navigateBack({})
						}
					})
				}
				
			},
			queryClassAppMenu(){
				let params = {}
				if(getToken('version') == 1){
					params = {
						parentMenuNo:'ydylapp200',
						craftsmanId:getToken('useNum')
					}
				}else{
					params = {
						parentMenuNo:'ydylapp100',
						companyNo:getToken('useNum')
					}
				}
				queryClassAppMenu(params).then(res=>{
					if(res.data && res.data.code){
						let list = res.data && res.data.listData
						if(list && list.length){
							list.forEach(v=>{
								v.imgPath = 'https://www.ydylmold.cn/file/getPlayResource/176/'+v.menuImage
							})
						}
						this.dataInfo = res.data
					}
				})
			},
			previewImg(arr, index) {
				uni.previewImage({
					current: index || 0,
					urls: arr
				})
			},
		}
		
		
	}
</script>
<style lang="scss">
	.selectTemplate{
		background-color: #F8F8F8;
		padding-top: 40rpx;
		.imgStyle{
			//水平 垂直 模糊距离 阴影大小 颜色 inset：内阴影
			box-shadow: 0rpx 0rpx 20rpx 10rpx #B2DBFC;
		}
	}
</style>
